from concurrent.futures import ProcessPoolExecutor
import os

def worker(task_id):
    """子进程要执行的任务"""
    print(f"Process {os.getpid()} is working on task {task_id}")

if __name__ == '__main__':
    # 创建一个包含4个进程的进程池
    with ProcessPoolExecutor(max_workers=4) as executor:
        # 提交任务给进程池
        tasks = [executor.submit(worker, i) for i in range(10000)]

    print("所有任务已经完成")

